from django.db import models

# Create your models here.

class Shopkeeper(models.Model):
    name=models.CharField(max_length=50,verbose_name='姓名')
    age=models.CharField(max_length=50,verbose_name='年龄')
    # 自定义表名
    class Meta:
        db_table='shopkeeper'

class Shop(models.Model):
    name=models.CharField(max_length=50,verbose_name='名称')
    price=models.DecimalField(max_digits=7,decimal_places=2,verbose_name='价格')
    account=models.CharField(max_length=50,verbose_name='描述')
    picture=models.ImageField(verbose_name='图片')
    shopkeeper=models.ForeignKey(Shopkeeper,on_delete=models.CASCADE)
    # 自定义表名
    class Meta:
        db_table="shop"

#   创建班级表
class Class(models.Model):
    name=models.CharField(max_length=50,verbose_name='班级名称')
    type=models.IntegerField(default=1,verbose_name='name')
    class Meta:
        db_table='class'

#   创建课程表
class Couser(models.Model):
    name = models.CharField(max_length=50)
    # 加了个外键 还加了个方便反向拿数据的函数related_name跟嵌套序列化器匹配
    cla=models.ForeignKey(Class,on_delete=models.CASCADE,related_name='couser')
    class Meta:
        db_table='couser'

#   创建学生表
class Student(models.Model):
    name = models.CharField(max_length=50, verbose_name='姓名')
    username=models.CharField(max_length=100)
    password=models.CharField(max_length=300)
    cla=models.ForeignKey(Class,on_delete=models.CASCADE)

    class Meta:
        db_table = 'student'

#   创建分类表
class Cate(models.Model):
    name=models.CharField(max_length=50,verbose_name='名称')
    class Meta:
        db_table='cate'

# 创建商品表
class Show_Shop(models.Model):
    name=models.CharField(max_length=50,verbose_name='商品名称')
    price=models.CharField(max_length=50,verbose_name='商品价格')
    cate=models.ForeignKey(Cate,on_delete=models.CASCADE)
    class Meta:
        db_table='showshop'

# 创建用户表
class User(models.Model):
    username=models.CharField(max_length=50,verbose_name='用户名')
    password=models.CharField(max_length=50,verbose_name='密码')
    class Meta:
        db_table='user'

# 创建老师表
class Teacher(models.Model):
    username=models.CharField(max_length=50,unique=True,verbose_name='用户名')
    password=models.CharField(max_length=50,verbose_name='密码')
    class Meta:
        db_table='teacher'

# 创建学生表
class Xstudent(models.Model):
    name=models.CharField(max_length=50,unique=True,verbose_name='姓名')
    age=models.IntegerField(verbose_name='年龄')
    teach=models.ForeignKey(Teacher,on_delete=models.SET_NULL,null=True,blank=True)
    class Meta:
        db_table='xstudent'

# 创建一张新的商品表
class XShop(models.Model):
    name=models.CharField(max_length=50,verbose_name='名称')
    price=models.DecimalField(max_digits=7,decimal_places=2,verbose_name='价格')
    count=models.ImageField(default=0,verbose_name='总评价数')
    comment=models.CharField(max_length=50,verbose_name='评价内容')
    class Meta:
        db_table='xshop'

# 创建一张新用户表
class Xuser(models.Model):
    username=models.CharField(max_length=50,verbose_name='名称')
    password=models.CharField(max_length=50,verbose_name='密码')
    class Meta:
        db_table='xuser'

# 创建一张用户表
class XU(models.Model):
    username=models.CharField(max_length=50,verbose_name='用户名')
    password=models.CharField(max_length=50,verbose_name='密码')
    class Meta:
        db_table='xu'

# 创建一张校区表
class School(models.Model):
    name=models.CharField(max_length=50,verbose_name='校区名称')
    state=models.CharField(max_length=50,verbose_name='校区说明')
    class Meta:
        db_table='school'

# 创建一张班级表
class Xclass(models.Model):
    name=models.CharField(max_length=50,verbose_name='班级名称')
    state=models.CharField(max_length=50,verbose_name='班级说明')
    school=models.ForeignKey(School,on_delete=models.CASCADE)
    class Meta:
        db_table='xclass'

# 创建一张学员表
class Xst(models.Model):
    name=models.CharField(max_length=50,verbose_name='姓名')
    gender=models.CharField(max_length=50,verbose_name='年龄')
    age=models.IntegerField(verbose_name='年龄')
    tel=models.IntegerField(verbose_name='手机')
    school=models.ForeignKey(School,on_delete=models.CASCADE)
    cla=models.ForeignKey(Class,on_delete=models.CASCADE)
    user=models.ForeignKey(XU,on_delete=models.CASCADE)
    class Meta:
        db_table='xst'